import { defineStore } from 'pinia'
import {
  getFindDoctorWallet,
  getFindDoctorIncomeRecordList,
  // getFindDoctorDrawRecordList,
  getDrawCash,
  getFindDoctorList
} from '../api/wallet'
// import dayjs from 'dayjs'
// import { ref } from 'vue'

export const usecurrentStore = defineStore('user', {
  state: () => ({
    list: [],
    incomerecordlist: [],
    drawrecordlist: [],
    drawcash: [],
    doctorlist: [],
    doctorId: JSON.parse(localStorage.getItem('doctorId') || '{}'),
    sessionId: JSON.parse(localStorage.getItem('sessionId') || '{}')
  }),
  actions: {
    // 查询医生钱包
    async handmony(doctorId: number, sessionId: string) {
      try {
        const getmonylist = await getFindDoctorWallet(doctorId, sessionId)
        console.log(getmonylist, '查询医生钱包 ')
        this.$state.list = getmonylist.data.result
        console.log(this.$state.list, '查询医生钱包mywallet')
      } catch (error) {
        console.log(error, '失败')
      }
    },
    // 查询医生收支记录
    async DoctorIncomeRecordList(doctorId: number, sessionId: string, page: number, count: number) {
      try {
        const getcomerecord = await getFindDoctorIncomeRecordList(doctorId, sessionId, {
          page,
          count
        })
        console.log(getcomerecord, '查询医生收支记录')
        this.$state.incomerecordlist = getcomerecord.data.result
        console.log(this.$state.incomerecordlist, '查询医生收支记录shouzhi')
        // this.$state.HbRecord = getcomerecord.data.result
        // this.$state.HbRecord.forEcach((item: any, index: number) => {
        //   console.log(item.createTime)
        //   const timestamp = item.createTime
        //   const formattedDate = ref('')
        //   if (timestamp) {
        //     formattedDate.value = dayjs.unix(timestamp).format('MM-DD')
        //   }
        //   this.$state.HbRecord[index].createTime = formattedDate.value
        // })
      } catch (error) {
        console.log(error, '失败')
      }
    },
    // 提现接口//提现
    async DrawCash(doctorId: number, sessionId: string, money: number) {
      try {
        const getdrawcash = await getDrawCash(doctorId, sessionId, money)
        // const getdrawcash=await getDrawCash(doctorId,sessionId,{money})
        console.log(getdrawcash, '提现接口')
        this.$state.drawcash = getdrawcash.data.result
        console.log(this.$state.drawcash, '提现接口1231231231')
      } catch (error) {
        console.log(error, '失败')
      }
    },
    //提现记录接口
    // async DoctorDrawRecordList(doctorId: number, sessionId: string, page: number, count: number) {
    //   try {
    //     const getdrawrecordlist = await getFindDoctorDrawRecordList(doctorId, sessionId, {
    //       page,
    //       count
    //     })
    //     console.log(getdrawrecordlist, '提现记录接口')
    //     this.$state.drawrecordlist = getdrawrecordlist.data.result
    //     console.log(this.$state.drawrecordlist, '提现记录接口1231231231')
    //   } catch (error) {
    //     console.log(error, '失败')
    //   }
    // },
    // 查询问诊医生列表
    async FindDoctorList(
      deptId: number,
      condition: number,
      sortBy: number,
      page: number,
      count: number
    ) {
      try {
        const getdoctorlist = await getFindDoctorList(deptId, condition, sortBy, page, count)
        console.log(getdoctorlist, '查询医生列表')
        this.$state.doctorlist = getdoctorlist.data.result
        console.log(this.$state.doctorlist, '查询医生列表1231231231')
      } catch (error) {
        console.log(error, '失败')
      }
    }
  }
})
